package day11.relect;

import org.junit.Test;

import java.lang.reflect.Constructor;

public class Demo3 {
    @Test
    public void test(){
        Class<?> class1 = Student.class;
        //获取所有的public的构造器
        Constructor<?>[] cs = class1.getConstructors();
        //打印构造器个数
        System.out.println(cs.length);

        //循环
        for (Constructor<?> c : cs) {
            System.out.println(c);
        }
    }

    @Test
    public void test2(){
        Class<?> class1 = Student.class;
        Constructor<?>[] cs = class1.getDeclaredConstructors();
        System.out.println("所有的构造器:" + cs.length);
        // 循环
        for (Constructor<?> c : cs) {
            System.out.println(c);
        }
    }

    //获取私有的构造器
    @Test
    public void test3() throws Exception{
        Class<?> class1 = Student.class;
        Constructor<?> default_C = class1.getDeclaredConstructor(String.class);
        System.out.println(default_C);
    }
}
